﻿using System.Text;
using System.Linq;
using System.Web;
using MBA.FluentExt.Ext;

namespace MBA.FluentExt
{
	
	public static class X
	{

		public static HtmlString ExtScript(params ExtObject[] components)
		{
			var sb = new StringBuilder();

			sb.Append("<script type=\"text/javascript\">\r\n");
			sb.Append("Ext.onReady(function(){\r\n");
			sb.Append(string.Join("\r\n", components.Select(c => c.ToJavascriptVar())));
			sb.AppendLine();
			sb.AppendLine("});");
			sb.Append("</script>");

			return new HtmlString(sb.ToString());
		}

		/// <summary>
		/// Simple Button class.
		/// </summary>
		/// <param name="id">The unique id of this component (defaults to an auto-assigned id). You should assign an id if you need to be able to access the component later and you do not have an object reference available (e.g., using Ext.getCmp).</param>
		public static Button Button(string id = null)
		{
			var b = new Button();

			if(id != null)
			{
				b.Id(id);
			}

			return b;
		}

	}

}
